﻿Namespace Admin

    Public Class PagesController
        Inherits AdminController

        Function Index(Optional pageIndex As Integer = 0) As ActionResult
            Dim pageSize As Double = My.Settings.PageSize
            ViewBag.PageIndex = pageIndex
            ViewBag.PageCount = CInt(Math.Ceiling(CDbl(Db.Pages.Count) / pageSize))

            ViewBag.Title = "Список страниц"
            Return View(Db.Pages.OrderBy(Function(m) m.Title).Skip(pageIndex * CInt(pageSize)).Take(CInt(pageSize)).ToList())
        End Function

        Function Edit(id As Guid) As ActionResult
            ViewBag.Title = "Редактирование страницы"
            Return View(Db.Pages.Find(id))
        End Function

        <HttpPost()>
        <ValidateAntiForgeryToken()>
        Function Edit(model As Page, returnUrl As String) As ActionResult
            If ModelState.IsValid Then
                Db.Entry(model).State = EntityState.Modified
                Db.SaveChanges()

                Return RedirectToLocal(returnUrl)
            End If

            ViewBag.Title = "Редактирование страницы"
            Return View(model)
        End Function

    End Class

End Namespace
